import { message } from 'antd';
import { GIcon, GModalForm, GTable } from 'geminis-react';
import { useRef } from 'react';

export default () => {
  const table = useRef<any>();


  const schema = {
    headerTitle: '成本记录',
    data: {
      url: '/api/cost/workflow/workflowCost',
      sort: 'startTime:desc',
    },
    toolBarRender: () => [
      <GModalForm
        button={{
          text: '计算成本',
          button: {
            icon: <GIcon type="icon-start" />,
          },
        }}
        form={{
          schema: {
            data: {
              url: '/api/cost/workflow/workflowCost/compute',
              methodSubmit: 'post',
              format: 'form',
            },
          },
          schemaPath: '/cost-pc/schema/workflow/cost/form.json',
          onSubmitted: () => {
            message.success('成功');
            table.current.loadData();
          },
        }}
      />,
    ],
  };

  return (
    <GTable
      ref={table}
      schema={schema}
      schemaPath="/cost-pc/schema/workflow/cost/table.json"
    />
  );
};
